import collections
class FrontMiddleBackQueue(object):

    def __init__(self):
        self.st = collections.deque()

    def pushFront(self, val):
        """
        :type val: int
        :rtype: None
        """
        self.st.appendleft(val)


    def pushMiddle(self, val):
        """
        :type val: int
        :rtype: None
        """
        index = len(self.st) // 2
        self.st.insert(index, val)


    def pushBack(self, val):
        """
        :type val: int
        :rtype: None
        """
        self.st.append(val)


    def popFront(self):
        """
        :rtype: int
        """
        if not self.st:
            return -1
        return self.st.popleft()


    def popMiddle(self):
        """
        :rtype: int
        """
        if not self.st:
            return -1
        index = (len(self.st) - 1) // 2
        val = self.st[index]
        del self.st[index]
        return val


    def popBack(self):
        """
        :rtype: int
        """
        if not self.st:
            return -1
        return self.st.pop()